#include "stdafx.h"
#include "UIUntil.h"

NAMESPACE_UI_BEGIN

static IPlatform * g_pPlatform = nullptr;
static IRender * g_pRender = nullptr;
static IDevice * g_pDevice = nullptr;
static ITextEngine * g_pTextEngine = nullptr;

void InitialUI(IPlatform * pPlatform, IDevice * pDevice, IRender * pRender, ITextEngine * pTextEngine)
{
	g_pPlatform = pPlatform;
	g_pDevice = pDevice;
	g_pRender = pRender;
	g_pTextEngine = pTextEngine;
}

void UnInitialUI()
{

}

IPlatform * GetPlatform()
{
	if(!g_pPlatform)
		throw CBadStateException();
	return g_pPlatform;
}
IRender * GetRender()
{
	if(!g_pRender)
		throw CBadStateException();
	return g_pRender;
}

ITextEngine * GetTextEngine()
{
	if(!g_pTextEngine)
		throw CBadStateException();
	return g_pTextEngine;
}

IDevice * GetDevice()
{
	if(!g_pDevice)
		throw CBadStateException();
	return g_pDevice;
}
IMouse * GetMouse()
{
	if(!g_pDevice)
		throw CBadStateException();
	IMouse * pMouse = g_pDevice->GetMouse();
	if(!pMouse)
		throw CBadStateException();
	return pMouse;
	
}
IKeyboard * GetKeyboard()
{
	if(!g_pDevice)
		throw CBadStateException();
	IKeyboard * pKeyboard = g_pDevice->GetKeybord();
	if(!pKeyboard)
		throw CBadStateException();
	return pKeyboard;
}
IScreen * GetScreen()
{
	if(!g_pDevice)
		throw CBadStateException();
	IScreen * pScreen = g_pDevice->GetScreen();
	if(!pScreen)
		throw CBadStateException();
	return pScreen;
}

NAMESPACE_UI_END